package com.hxit.huaxiamelongarden.controller;

import com.hxit.huaxiamelongarden.domin.dto.CommentDto;
import com.hxit.huaxiamelongarden.domin.po.Comment;
import com.hxit.huaxiamelongarden.service.CommentService;
import com.hxit.huaxiamelongarden.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CommentController
 * @description 评论控制层
 * @Author 12694
 * @Date 2025/1/30 14:55
 * @Version 1.0
 **/
@RestController
@Slf4j
@Tag(name = "评论模块", description = "评论模块")
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;
    //查询评论
    @Operation(summary = "查询评论")
    @GetMapping
    public Result queryComment(@RequestParam("contentId") Integer ContentId){
        List<Comment> commentList = commentService.getByContentId(ContentId);
        return Result.success(commentList);
    }
    //添加评论
    @Operation(summary = "添加评论")
    @PostMapping("/add")
    public Result addComment(@RequestBody CommentDto commentDto,@RequestAttribute("userId") String userId){
        commentDto.setUserId(Integer.valueOf(userId));
        commentService.addComment(commentDto);
        return Result.success();
    }
}
